<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .cls {
            background-color: black;
        }
    </style>
</head>

<body class="">
    <input type="button" value="关灯" id="bn">
    <script>
     function my$(id){
         return document.getElementById(id);
     }
     
     my$("bn").onclick = function (){
         document.body.className = document.body.className  != "cls" ? "cls" : "" ;
         this.value = document.body.className  != "cls" ? "关灯" : "开灯"
     }


    </script>
</body>

</html>